var js=document.scripts;
var jsPath;
for(var i=js.length;i>0;i--){
    if(js[i-1].src.indexOf("fsd.all.js")>-1){
        jsPath=js[i-1].src.substring(0,js[i-1].src.lastIndexOf("/")+1);
    }
}
var api = frameElement.api, W = api.opener;
var imgsrc = api.data;
var path = '../../../';
$(document).ready(function(){
    if(imgsrc != null && imgsrc != ""){
        var html = "<img id='fsdimgview' onclick='clickimg();' src='"+jsPath+path+imgsrc+"' />"
        $(html).appendTo("#fsdimgcontent");
    }
});

function makeYtHtml(){
 if(imgsrc != null && imgsrc != ""){
        var html = "<img id='fsdimgview' onclick='clickimg();' src='"+jsPath+path+imgsrc+"' />"
        //$(html).appendTo("#fsdimgcontent");
        $("#fsdimgcontent").html(html);//替换里面的内容
    }
}

function makeSfHtml(){
    var img = new Image();
    img.onload = function(){
        var imgwidth = img.width;
        var imgheight = img.height;
        var windowwidth = api.config.width.substr(0 , api.config.width.length - 2);
        var windowheight = api.config.height.substr(0 , api.config.height.length - 2);
        
        var w = imgwidth;
        var h = imgheight;
        
        if(imgwidth > imgheight){
            if(imgwidth > windowwidth){
                var  bl = (imgwidth - windowwidth) / imgwidth;
                w = windowwidth;
                h = imgheight - (imgheight * bl)
            }
        }else if(imgwidth < imgheight){
            if(imgheight > windowheight){
                var bl = (imgheight - windowheight) / imgheight;
                h = windowheight;
                w = imgwidth - (imgwidth * bl);
            }
        }else if(imgwidth == imgheight){
            if(imgheight > windowheight){
                w = windowheight;
                h = windowheight;
            }
        }
        
        var html = "<img width='" + w + "' height=' " + h + " ' onclick='clickimg();' id='fsdimgview' src='" + jsPath + path + imgsrc + "' />"
            //$(html).appendTo("#fsdimgcontent");
        $("#fsdimgcontent").html(html);//替换里面的内容
    };
    img.src =$('#fsdimgview').attr("src") ;
   
}

var clickimg = function(){
    api.close();
}


